package transactions.dq.historyarchives;

import transactions.dq.StringUtilForName;
import dinamica.*;

/**
 * @author anthony 2010-4-16
 * */
public class UpdateMaster extends dinamica.audit.AuditableTransaction {
	public int service(Recordset inputParams) throws Throwable {
		// reuse superclass code
		int rc = super.service(inputParams);

		// get db object and save record with empty blob
		Db db = getDb();

		// 插入t_master
		String sqlUpdateMaster = getResource("update.sql");
		sqlUpdateMaster = getSQL(sqlUpdateMaster, inputParams);

		// 汉字名字转换成字母存放在master_chars
		String master_name = inputParams.getString("master_name");
		String charsStr = StringUtilForName.getFirstLetter(master_name);
		sqlUpdateMaster = StringUtil.replace(sqlUpdateMaster, "${master_chars}", charsStr);

		db.exec(sqlUpdateMaster);

		// (1)插入t_master_detail
		String sqlInsertMasterDetail = getResource("update_master-detail.sql");
		sqlInsertMasterDetail = getSQL(sqlInsertMasterDetail, inputParams);
		db.exec(sqlInsertMasterDetail);

		// (4)插入t_Placement(移至回迁安置界面维护)
		String sqlInsertPlacement = getResource("update_placement.sql");
		sqlInsertPlacement = getSQL(sqlInsertPlacement, inputParams);
		db.exec(sqlInsertPlacement);
		
		// (6)插入t_archives
		String sqlUpdateArchives = getResource("update_archives.sql");
		sqlUpdateArchives = getSQL(sqlUpdateArchives, inputParams);
		db.exec(sqlUpdateArchives);
		return rc;

	}

}
